package com.ll.xiaonew.commons.core.exception;

import com.ll.xiaonew.commons.core.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author new
 * @date 2022/12/5 11:45
 */
@Slf4j
@RestControllerAdvice//全局异常管理器
public class GSysException {
    @ExceptionHandler(Exception.class)
    public R systemException(Exception e){
        //记录异常
        log.error("系统出错",e);

        return R.erro("系统繁忙，稍后再试！");
    }


    /**
     * @author new
     * @Description: 只有抛出的异常是BusinessException的子类才会掉用这个方法
     * @date 2022/12/5 15:15
     */
    @ExceptionHandler(BusinessException.class)
    public R businessException(BusinessException e){
        log.error("系统异常",e);
        return R.erro(e.getMsg()).put("code",e.getCode());
    }
}
